package com.starview.star.operators.pio.runtime;

import java.nio.charset.Charset;
import java.nio.ByteBuffer;

public class SerializeString {
  /* result ByeBuffer already flipped, ready for reading */
  public static ByteBuffer __string_to_utf8(String s) {
    ByteBuffer bb = Charset.forName("UTF-8").encode(s);
    return bb;
  }

  @SuppressWarnings("unused")
  private static void print_byte_array(byte[] ba) {
    for (byte b: ba) {
      System.err.print(String.format("%02X ", b));
    }
  }

  public static String __string_of_utf8(ByteBuffer bb) {
    return Charset.forName("UTF-8").decode(bb).toString();
  }
}
